package com.servlet.article;

import com.entity.Article;
import com.entity.Code;
import com.service.ArticleService;
import com.utils.JsonUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 查询全部文章，每页分页，一次性返回全部文章
 */
@WebServlet("/allArticle")
public class AllArticle extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArticleService articleService = new ArticleService();
        List<Article> allArticle =articleService.findAllArticle();
        request.setCharacterEncoding("utf-8");
        Code code = new Code();
        code.setData(allArticle);
        code.setMsg("文章查询成功");
        code.setCode("200");
        JsonUtil jsonUtil = new JsonUtil();
        String s = jsonUtil.JavaToJson(code);
        response.setCharacterEncoding("utf-8");
        response.getWriter().print(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }
}
